package service

import (
	"github.com/dgrijalva/jwt-go"
	"log"
	"time"
	"writerhelper/global"
	"writerhelper/middleware"
	"writerhelper/model"
)


func GenerateJwt(u *model.User) string {
	global.MySigningKey = []byte("gcc")
	MyClaims := middleware.MyClaims{
		Email: u.Email,
		StandardClaims:jwt.StandardClaims{
			ExpiresAt: time.Now().Unix()+60*60*24*7,
			Issuer:"gcc",

		},
	}
	tokenString := jwt.NewWithClaims(jwt.SigningMethodHS256, MyClaims)
	token, err := tokenString.SignedString(global.MySigningKey)
	if err != nil {
		log.Fatal("token加密失败",err)
	}
	return token
}

